<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="utf-8"%>
   <%@ include file="/WEB-INF/jsp/common.jsp"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src='${pageContext.request.contextPath}/resource/js/jquery/jquery-1.12.4.min.js'></script>
			<link href='${pageContext.request.contextPath}/resource/css/def/bootstrap/css/bootstrap.min.css'></link>
		<script type="text/javascript">
			$(function(){
				
				selectAll();
				
			})
			function addMenu(){
				
				$("#addMenuform").submit();
				
			}
			function update(id){
				$("#hidden").attr("value",id);
				
				
			}
			function selectAll(){
					$.ajax({
						url:"selectAll.action",
						dataType:"json",
						type:"post",
						success:function(data){
							var list = data.list;
							var table="<table class='table table-striped'><tr><td>id</td><td>name</td><td>parent_id</td><td>permission_id</td><td>staff_org_id</td><td></td><td></td></tr>";
							$.each(list,function(i,Menu){
							table+="<tr><td>"+Menu.id+"</td><td>"+Menu.name+"</td><td>"+Menu.parentId+"</td><td>"+Menu.permissionId+"</td><td>"+Menu.staffOrgId+"</td><td>";
							table+="<button type='button' class='btnupdata' data-toggle='modal' data-target='#menuModal'  onclick='update("+Menu.id+")'>更改</button></td><td><button onclick='delect("+Menu.id+")'>删除</button></td></tr>";
						})
							table+="</table>";
							$("#table").html(table);
						}
						
					})	
				
				
			}
			
			function updateMenu(){
				$("#updateMenuform").submit();
			}
			function delect(id){
				$.ajax({
					url:"delectMenuById.action",
					data:"id="+id,
					type:"post",
					dataType:"json",
					success:function(data){
						
						selectAll();
					}
					
				})
				
				
			}
			
			
					
			</script>
</head>
<body>
		
        
		

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#orgModal">
	新增Menu
</button>

<div class="modal fade" id="orgModal" tabindex="-1" role="dialog" aria-labelledby="orgModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="orgModalLabel">menu</h4>
      </div>
      <div class="modal-body">
        	<form action="addMenu.action" method="post" id="addMenuform">
        			
        		name:<input type="text" name="name" /><br/>
        		parent_id:<input type="text" name="parent_id"/><br/>
        		permission_id:<input type="text" name="permission_id"/><br/>
        		
        		staff_org_id:<input type="text" name="staff_org_id"/><br/>
        	</form>		
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" onclick="addMenu()">Save</button>
      </div>
    </div>
  </div>
</div>
		
 <div id="table"></div>
	<div class="modal fade" id="menuModal" tabindex="-1" role="dialog" aria-labelledby="orgModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="orgModalLabel">menu</h4>
      </div>
      <div class="modal-body">
        	<form action="updateMenu.action" method="post" id="updateMenuform">
        			<input id="hidden" type="hidden" name="id" />
        		name:<input type="text" name="name" /><br/>
        		parent_id:<input type="text" name="parent_id"/><br/>
        		permission_id:<input type="text" name="permission_id"/><br/>
        		
        		staff_org_id:<input type="text" name="staff_org_id"/><br/>
        	</form>		
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" onclick="updateMenu()">Save</button>
      </div>
    </div>
  </div>
</div>		
</body>
</html>